package com.lipiao.traveltreasure.controller.restaurant;

import com.lipiao.traveltreasure.bean.restaurantBean.Food;
import com.lipiao.traveltreasure.service.restaurant.CommonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.Part;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 商家 客户通用接口
 * 1.查询菜单信息
 */
@Api(tags = "点餐小程序-通用")
@Controller
@RequestMapping(value = "/restaurantApi/common")
public class CommonController {

    //存储预返回页面的结果对象
    private Map<String, Object> result;

    //注入业务对象
    @Resource
    private CommonService commonService;


    //  get  localhost:8080/restaurantApi/common/queryAllFood
    @ApiOperation(value = "查询所有菜单信息", notes = "注意事项：GET请求，无参数；菜品信息中主食是0，小菜是1，饮料是2")
    @GetMapping("/queryAllFood")
    @ResponseBody
    public Map<String, Object> queryAllFood() {
        //防止返回信息重复
        result = new HashMap<>();
        try {
//            List<Food> foodList1 = commonService.queryFoodByType("主食");
//            List<Food> foodList2 = commonService.queryFoodByType("小菜");
//            List<Food> foodList3 = commonService.queryFoodByType("饮料");
//            HashMap<String,List<Food>> foodList=new HashMap<>();
//            foodList.put("主食",foodList1);
//            foodList.put("小菜",foodList2);
//            foodList.put("饮料",foodList3);
            List<Food> foodList = commonService.queryAllFood();
            result.put("Result", "查询菜品信息成功");
            result.put("FoodList", foodList);
        } catch (Exception e) {
            e.printStackTrace();
            result.put("Result", "查询菜品信息失败");
            result.put("FoodList", "");
        }
        return result;
    }

    //  get  localhost:8080/restaurantApi/common/queryFoodById
    //按照菜品id查询
    @ApiOperation(value = "按照菜品id查询菜单信息", notes = "注意事项：GET请求，参数String id")
    @GetMapping("/queryFoodById")
    @ResponseBody
    public Map<String, Object> queryFoodById(String id) {
        //防止返回信息重复
        result = new HashMap<>();
        try {
            Food food = commonService.queryFoodById(id);
            result.put("Result", "查询菜品信息成功");
            result.put("Food", food);
        } catch (Exception e) {
            e.printStackTrace();
            result.put("Result", "查询菜品信息失败");
            result.put("Food", "");
        }
        return result;
    }

    //get  localhost:8080/restaurantApi/common/queryFoodByType
    // //按照菜品类别查询菜单信息
    @ApiOperation(value = "按照菜品类别查询菜单信息", notes = "注意事项：GET请求，参数int type；主食是0，小菜是1，饮料是2")
    @GetMapping("/queryFoodByType")
    @ResponseBody
    public Map<String, Object> queryFoodByType(int type) {
        //防止返回信息重复
        result = new HashMap<>();
        try {
            List<Food> foodList = commonService.queryFoodByType(type);
            result.put("Result", "查询菜品信息成功");
            result.put("FoodList", foodList);
        } catch (Exception e) {
            e.printStackTrace();
            result.put("Result", "查询菜品信息失败");
            result.put("Food", "");
        }
        return result;
    }

}
